Allow debuginfo level to be specified
authorSteven Fackler <sfackler@gmail.com>
Thu, 12 Jan 2017 05:35:17 +0000 (21:35 -0800)
committerSteven Fackler <sfackler@gmail.com>
Fri, 13 Jan 2017 04:11:29 +0000 (20:11 -0800)
`true` is mapped to `2`, which matches current behavior.

13 files changed:
src/cargo/core/manifest.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/util/toml.rs
src/doc/manifest.md
tests/build-lib.rs
tests/build-script.rs
tests/build.rs
tests/cross-compile.rs
tests/profiles.rs
tests/run.rs
tests/rustc.rs

index 530fffc7f8a2d48f428fd05d9352a5ff0e5ee0a6..204d55a1ea6a29dba61c5446de95f79f1eb24a7c 100644 (file)
@@ -130,7 +130,7 @@ pub struct Profile {
     pub codegen_units: Option<u32>,    // None = use rustc default
     pub rustc_args: Option<Vec<String>>,
     pub rustdoc_args: Option<Vec<String>>,
-    pub debuginfo: bool,
+    pub debuginfo: Option<u32>,
     pub debug_assertions: bool,
     pub rpath: bool,
     pub test: bool,
@@ -143,7 +143,7 @@ pub struct Profile {
 #[derive(RustcEncodable)]
 struct SerializedProfile<'a> {
     opt_level: &'a str,
-    debuginfo: bool,
+    debuginfo: Option<u32>,
     debug_assertions: bool,
     test: bool,
 }
@@ -488,7 +488,7 @@ impl fmt::Display for Target {
 impl Profile {
     pub fn default_dev() -> Profile {
         Profile {
-            debuginfo: true,
+            debuginfo: Some(2),
             debug_assertions: true,
             ..Profile::default()
         }
@@ -497,7 +497,7 @@ impl Profile {
     pub fn default_release() -> Profile {
         Profile {
             opt_level: "3".to_string(),
-            debuginfo: false,
+            debuginfo: None,
             ..Profile::default()
         }
     }
@@ -554,7 +554,7 @@ impl Default for Profile {
             codegen_units: None,
             rustc_args: None,
             rustdoc_args: None,
-            debuginfo: false,
+            debuginfo: None,
             debug_assertions: false,
             rpath: false,
             test: false,
index 2d2c31c3b199d4cb395e05aea8ddc612862915a0..ea3e0f98ca244ec78a5eb21cbd7633192c0b623e 100644 (file)
@@ -107,7 +107,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
            Kind::Host => cx.host_triple(),
            Kind::Target => cx.target_triple(),
        })
-       .env("DEBUG", &profile.debuginfo.to_string())
+       .env("DEBUG", &profile.debuginfo.is_some().to_string())
        .env("OPT_LEVEL", &profile.opt_level)
        .env("PROFILE", if cx.build_config.release { "release" } else { "debug" })
        .env("HOST", cx.host_triple())
index 1cdf5bb047ac9a8383dde20c7f0800ea773a1185..23a71ae8d3edc56e32d27437d257e7effbb8628e 100644 (file)
@@ -201,7 +201,7 @@ impl<'a> JobQueue<'a> {
         let profile = cx.lib_profile();
         let mut opt_type = String::from(if profile.opt_level == "0" { "unoptimized" }
                                         else { "optimized" });
-        if profile.debuginfo {
+        if profile.debuginfo.is_some() {
             opt_type = opt_type + " + debuginfo";
         }
         let duration = start_time.elapsed();
index 162f985095e263e20381f5448f2412cfa290f0ce..370b7e1dca41a1cf394bd97869aa18c6c563b9ac 100644 (file)
@@ -94,7 +94,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
                                      resolve: &'a Resolve,
                                      config: &'cfg Config,
                                      build_config: BuildConfig,
-                                     profiles: &'a Profiles, 
+                                     profiles: &'a Profiles,
                                      exec: Arc<Executor>)
                                      -> CargoResult<Compilation<'cfg>> {
     let units = pkg_targets.iter().flat_map(|&(pkg, ref targets)| {
@@ -659,8 +659,8 @@ fn build_base_args(cx: &mut Context,
         }
     }
 
-    if debuginfo {
-        cmd.arg("-g");
+    if let Some(debuginfo) = debuginfo {
+        cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
     }
 
     if let Some(ref args) = *rustc_args {
index ecfcd0fcf8386f9c5a4b46f3ea429f1279a5546f..3bcbe7c9550ee2c16d6f8d2b2b16911aaf898551 100644 (file)
@@ -276,12 +276,18 @@ impl Decodable for TomlOptLevel {
     }
 }
 
+#[derive(RustcDecodable, Clone)]
+pub enum U32OrBool {
+    U32(u32),
+    Bool(bool),
+}
+
 #[derive(RustcDecodable, Clone, Default)]
 pub struct TomlProfile {
     opt_level: Option<TomlOptLevel>,
     lto: Option<bool>,
     codegen_units: Option<u32>,
-    debug: Option<bool>,
+    debug: Option<U32OrBool>,
     debug_assertions: Option<bool>,
     rpath: Option<bool>,
     panic: Option<String>,
@@ -1265,12 +1271,18 @@ fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles {
 
     fn merge(profile: Profile, toml: Option<&TomlProfile>) -> Profile {
         let &TomlProfile {
-            ref opt_level, lto, codegen_units, debug, debug_assertions, rpath,
+            ref opt_level, lto, codegen_units, ref debug, debug_assertions, rpath,
             ref panic
         } = match toml {
             Some(toml) => toml,
             None => return profile,
         };
+        let debug = match *debug {
+            Some(U32OrBool::U32(debug)) => Some(Some(debug)),
+            Some(U32OrBool::Bool(true)) => Some(Some(2)),
+            Some(U32OrBool::Bool(false)) => Some(None),
+            None => None,
+        };
         Profile {
             opt_level: opt_level.clone().unwrap_or(TomlOptLevel(profile.opt_level)).0,
             lto: lto.unwrap_or(profile.lto),
index 9aaab670738bb15c936cf00d40959d7c79c35915..ccdc6c3cc67878e27d36594373a66f99b6f07d6f 100644 (file)
@@ -181,7 +181,8 @@ along with the defaults for each profile.
 # The development profile, used for `cargo build`.
 [profile.dev]
 opt-level = 0      # controls the `--opt-level` the compiler builds with
-debug = true       # controls whether the compiler passes `-g`
+debug = true       # controls whether the compiler passes `-C debuginfo`
+                   # a value of `true` is equivalent to `2`
 rpath = false      # controls whether the compiler passes `-C rpath`
 lto = false        # controls `-C lto` for binaries and staticlibs
 debug-assertions = true # controls whether debug assertions are enabled
@@ -202,7 +203,7 @@ panic = 'unwind'
 # The testing profile, used for `cargo test`.
 [profile.test]
 opt-level = 0
-debug = true
+debug = 2
 rpath = false
 lto = false
 debug-assertions = true
@@ -222,7 +223,7 @@ panic = 'unwind'
 # The documentation profile, used for `cargo doc`.
 [profile.doc]
 opt-level = 0
-debug = true
+debug = 2
 rpath = false
 lto = false
 debug-assertions = true
index 28584b89d1f604d6065c253e36f416e48c898a39..7b9af2a484f3ade843878779be730573de3937ae 100644 (file)
@@ -8,7 +8,7 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
     format!("\
 [COMPILING] {name} v{version} ({url})
 [RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
index 9d206bd7816cdbf042185c4f8ba2711780668424..371434c494ea60064de585bbf51c549ab8a87254 100644 (file)
@@ -184,7 +184,7 @@ fn custom_build_script_rustc_flags() {
                 execs().with_status(101)
                        .with_stderr(&format!("\
 [COMPILING] bar v0.5.0 ({url})
-[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -g \
+[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -C debuginfo=2 \
         -C metadata=[..] \
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target \
@@ -766,19 +766,19 @@ fn build_cmd_with_a_build_cmd() {
 [RUNNING] `rustc [..] a[/]build.rs [..] --extern b=[..]`
 [RUNNING] `[..][/]a-[..][/]build-script-build`
 [RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib \
-    --emit=dep-info,link -g \
+    --emit=dep-info,link -C debuginfo=2 \
     -C metadata=[..] \
     --out-dir [..]target[/]debug[/]deps \
     -L [..]target[/]debug[/]deps`
 [COMPILING] foo v0.5.0 (file://[..])
 [RUNNING] `rustc --crate-name build_script_build build.rs --crate-type bin \
     --emit=dep-info,link \
-    -g -C metadata=[..] --out-dir [..] \
+    -C debuginfo=2 -C metadata=[..] --out-dir [..] \
     -L [..]target[/]debug[/]deps \
     --extern a=[..]liba[..].rlib`
 [RUNNING] `[..][/]foo-[..][/]build-script-build`
 [RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib \
-    --emit=dep-info,link -g \
+    --emit=dep-info,link -C debuginfo=2 \
     -C metadata=[..] \
     --out-dir [..] \
     -L [..]target[/]debug[/]deps`
index ce8f4c34642f6ee826843edbbd4ec28645a7d7ab..e4871a58dca4b8dd56b3f9af14d308ee5a0cc2dc 100644 (file)
@@ -821,13 +821,13 @@ fn cargo_default_env_metadata_env_var() {
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
         --emit=dep-info,link \
-        -C prefer-dynamic -g \
+        -C prefer-dynamic -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         -C extra-filename=[..] \
         --out-dir [..] \
@@ -848,13 +848,13 @@ suffix = env::consts::DLL_SUFFIX,
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
         --emit=dep-info,link \
-        -C prefer-dynamic -g \
+        -C prefer-dynamic -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         -C extra-filename=[..] \
         --out-dir [..] \
@@ -1198,7 +1198,7 @@ fn verbose_build() {
                 execs().with_status(0).with_stderr(&format!("\
 [COMPILING] test v0.0.0 ({url})
 [RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
@@ -2443,7 +2443,7 @@ fn compiler_json_error_format() {
         "reason":"compiler-artifact",
         "profile": {
             "debug_assertions": true,
-            "debuginfo": true,
+            "debuginfo": 2,
             "opt_level": "0",
             "test": false
         },
@@ -2475,7 +2475,7 @@ fn compiler_json_error_format() {
         "target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
         "profile": {
             "debug_assertions": true,
-            "debuginfo": true,
+            "debuginfo": 2,
             "opt_level": "0",
             "test": false
         },
@@ -2537,7 +2537,7 @@ fn message_format_json_forward_stderr() {
         "target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
         "profile":{
             "debug_assertions":true,
-            "debuginfo":true,
+            "debuginfo":2,
             "opt_level":"0",
             "test":false
         },
index bfa2a88f0fec406807edc4caabb0f0aee589d410..6ab9ed2ad181cbdbb1d50719f32ed1ceac5f657c 100644 (file)
@@ -432,7 +432,7 @@ fn linker_and_ar() {
                        .with_stderr_contains(&format!("\
 [COMPILING] foo v0.5.0 ({url})
 [RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin \
-    --emit=dep-info,link -g \
+    --emit=dep-info,link -C debuginfo=2 \
     -C metadata=[..] \
     --out-dir {dir}[/]target[/]{target}[/]debug[/]deps \
     --target {target} \
index 1dabb561e0c609300d26d2b614c288f3d1605c85..cf7c1b31e44372651ff318b8419bec81cba52589 100644 (file)
@@ -62,7 +62,38 @@ fn opt_level_override_0() {
 [COMPILING] test v0.0.0 ({url})
 [RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
         --emit=dep-info,link \
-        -g \
+        -C debuginfo=2 \
+        -C metadata=[..] \
+        --out-dir [..] \
+        -L dependency={dir}[/]target[/]debug[/]deps`
+[FINISHED] [..] target(s) in [..]
+",
+dir = p.root().display(),
+url = p.url()
+)));
+}
+
+#[test]
+fn debug_override_1() {
+    let mut p = project("foo");
+
+    p = p
+        .file("Cargo.toml", r#"
+            [package]
+            name = "test"
+            version = "0.0.0"
+            authors = []
+
+            [profile.dev]
+            debug = 1
+        "#)
+        .file("src/lib.rs", "");
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0).with_stderr(&format!("\
+[COMPILING] test v0.0.0 ({url})
+[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
+        --emit=dep-info,link \
+        -C debuginfo=1 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
@@ -93,7 +124,7 @@ fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
 [RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
         --emit=dep-info,link \
         -C opt-level={level} \
-        -g \
+        -C debuginfo=2 \
         -C debug-assertions=on \
         -C metadata=[..] \
         --out-dir [..] \
@@ -164,7 +195,7 @@ fn top_level_overrides_deps() {
         --emit=dep-info,link \
         -C prefer-dynamic \
         -C opt-level=1 \
-        -g \
+        -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir {dir}[/]target[/]release[/]deps \
         -L dependency={dir}[/]target[/]release[/]deps`
@@ -172,7 +203,7 @@ fn top_level_overrides_deps() {
 [RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
         --emit=dep-info,link \
         -C opt-level=1 \
-        -g \
+        -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]release[/]deps \
index d2df6da450c30cd2a71bef7d27df2ca1ab6862fd..bca7680cf1f305ffeb2829e8846828052967e6d6 100644 (file)
@@ -446,14 +446,14 @@ fast2"));
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \
         --emit=dep-info,link \
-        -g \
+        -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir {dir}[/]target[/]debug[/]deps \
         -L dependency={dir}[/]target[/]debug[/]deps`
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc --crate-name a examples[/]a.rs --crate-type bin \
         --emit=dep-info,link \
-        -g \
+        -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir {dir}[/]target[/]debug[/]examples \
         -L dependency={dir}[/]target[/]debug[/]deps \
index 03c1e69c24298b2ecae781de711cf061ded36dc3..5cec7bc3c80d55d7b03b2aa571b6afd1123d276f 100644 (file)
@@ -28,7 +28,7 @@ fn build_lib_for_foo() {
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
@@ -57,7 +57,7 @@ fn lib() {
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C debug-assertions=off \
         -C metadata=[..] \
         --out-dir [..] \
@@ -87,12 +87,12 @@ fn build_main_and_allow_unstable_options() {
                 .with_stderr(&format!("\
 [COMPILING] {name} v{version} ({url})
 [RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C metadata=[..] \
         --out-dir [..] \
         -L dependency={dir}[/]target[/]debug[/]deps`
 [RUNNING] `rustc --crate-name {name} src[/]main.rs --crate-type bin \
-        --emit=dep-info,link -g \
+        --emit=dep-info,link -C debuginfo=2 \
         -C debug-assertions \
         -C metadata=[..] \
         --out-dir [..] \
@@ -151,11 +151,11 @@ fn build_with_args_to_one_of_multiple_binaries() {
                 .with_status(0)
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
-[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -g \
-        -C metadata=[..] \
+[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
+        -C debuginfo=2 -C metadata=[..] \
         --out-dir [..]`
-[RUNNING] `rustc --crate-name bar src[/]bin[/]bar.rs --crate-type bin --emit=dep-info,link -g \
-        -C debug-assertions [..]`
+[RUNNING] `rustc --crate-name bar src[/]bin[/]bar.rs --crate-type bin --emit=dep-info,link \
+        -C debuginfo=2 -C debug-assertions [..]`
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
 ", url = p.url())));
 }
@@ -207,10 +207,10 @@ fn build_with_args_to_one_of_multiple_tests() {
                 .with_status(0)
                 .with_stderr(format!("\
 [COMPILING] foo v0.0.1 ({url})
-[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -g \
-        -C metadata=[..] \
+[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link \
+        -C debuginfo=2 -C metadata=[..] \
         --out-dir [..]`
-[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -g \
+[RUNNING] `rustc --crate-name bar tests[/]bar.rs --emit=dep-info,link -C debuginfo=2 \
         -C debug-assertions [..]--test[..]`
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
 ", url = p.url())));
@@ -251,9 +251,9 @@ fn build_foo_with_bar_dependency() {
                 .with_status(0)
                 .with_stderr(format!("\
 [COMPILING] bar v0.1.0 ([..])
-[RUNNING] `[..] -g [..]`
+[RUNNING] `[..] -C debuginfo=2 [..]`
 [COMPILING] foo v0.0.1 ({url})
-[RUNNING] `[..] -g -C debug-assertions [..]`
+[RUNNING] `[..] -C debuginfo=2 -C debug-assertions [..]`
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
 ", url = foo.url())));
 }